﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace Batalha_Estelar
{
    abstract class GameObject : IDisposable
    {
        public GameObject(Game game)
        {
            this.MyGame = game;
            this.Colision = false;
        }

        public Game MyGame { get; set; }

        public Texture2D Textura { get; protected set; }

        public Vector2 Posicao { get; protected set; }

        public Vector2 Direcao { get; set; }

        public bool Colision { get; set; }

        public abstract void Update(GameTime gameTime);

        public abstract void Draw(SpriteBatch spriteBatch);

        #region IDisposable Pattern

        private bool disposed = false;

        ~GameObject()
        {
            Dispose(false);
        }

        protected abstract void Dispose(bool disposing);

        public Rectangle GetBounds()
        {
            var rec = new Rectangle();

            rec.X = (int)Posicao.X;
            rec.Y = (int)Posicao.Y;

            if (Textura != null)
            {
                rec.Width = Textura.Width;
                rec.Height = Textura.Height;
            }

            return rec;
        }

        //EXEMPLO
        //protected virtual void Dispose(bool disposing)
        //{
        //    if (!disposed)
        //    {
        //        if (disposing)
        //        {
        //            // dispose-only, i.e. non-finalizable logic
        //        }

        //        // shared cleanup logic
        //        disposed = true;
        //    }
        //}

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        #endregion

    }
}
